import { Injectable } from '@angular/core';
import {Http} from "@angular/http";
import {Observable} from "rxjs/Observable";

@Injectable()
export class DepartmentService {

  constructor(private http:Http) { }

  list(parentCode:string):Observable<any[]> {
    return new Observable((observer) => {
      this.http.get('assets/data/department.json').map(res => res.json()).subscribe((data) => {
        if((parentCode||'')==''){
          observer.next(data)
          observer.complete()
        }else{
          observer.next(data.filter(item => item['parentCode']==parentCode))
          observer.complete()
        }
      })
    })
  }
}
